package com.example.demo.server.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.mapper.WalletMapper;
import com.example.demo.pojo.Minute;
import com.example.demo.pojo.Wallets;
import com.example.demo.server.MinuteService;
import com.example.demo.server.WalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class WalletServiceImpl
        extends ServiceImpl<WalletMapper, Wallets>
        implements WalletService {

    @Autowired
    private MinuteService minuteService;


    /**
     * 交易明细
     * @param id 交易id
     * @param money 交易金额
     * @param balance 当前余额
     * @param type 交易类型
     */
    @Override
    @Transactional
    public void deal(Integer id, Double money, Double balance, String type) {
        // 根据钱包id插入记录
        Minute minute = new Minute();
        minute.setWallet_id(id);
        minute.setAmount(money);
        minute.setBalance_at(balance);
        minute.setType(type);
        minuteService.save(minute);
    }

    @Override
    public List<Minute> getAllMinute(LambdaQueryWrapper<Minute> lamb) {
        List<Minute> list = minuteService.list(lamb);
        System.out.println(list);
        return list;
    }
}
